package com.example.superoa.controller;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.alibaba.fastjson.JSONArray;
import com.example.superoa.common.Shijian;
import com.example.superoa.model.pojos.CalendarYf;
import com.example.superoa.model.service.CalendarYfService;
import com.example.superoa.model.service.DepartmentService;
import com.example.superoa.model.service.TrainService;

@Controller
//日历
@SessionAttributes({"manylist","nots"})
public class CalenderController {
	@Autowired
	public CalendarYfService cy;
	@Autowired
	public DepartmentService ds;
	@Autowired
	public TrainService ts;
	
	Shijian sj=new Shijian();
	
	@RequestMapping("dome")
	public void dome(Model model,HttpSession session) {
		int  staff_id=Integer.valueOf(session.getAttribute("sid").toString());//获取当前员工id
		Date date=new Date(sj.getNetworkTime());
		String today=(date.getYear()+1900)+","+(date.getMonth()+1)+","+date.getDate();
		model.addAttribute("today", today);
		System.err.println("网络时间："+today);
		model.addAttribute("manylist", cy.selectCalendarByid(today,staff_id));
		System.err.println("---"+cy.findMany(today));
		int id=Integer.parseInt(session.getAttribute("sid").toString());
		System.err.println(id+"---"+ts.noticestaff(id, date));
		model.addAttribute("nots", ts.noticestaff(id, date));
		
	}
	
	@RequestMapping("savecalendar")
	@ResponseBody
	public void savecalender(String a,String b,String c,Model model,HttpSession session) {
		int  staff_id=Integer.valueOf(session.getAttribute("sid").toString());//获取当前员工id
		cy.addCalender(a,b,c,staff_id);
	}
	
	@RequestMapping("selecttoday")
	@ResponseBody
	public JSONArray selecttoday(String a,Model model,HttpSession session) {
		int  staff_id=Integer.valueOf(session.getAttribute("sid").toString());//获取当前员工id
		Date date=new Date(sj.getNetworkTime());
		model.addAttribute("manylist", cy.selectCalendarByid(a,staff_id));
		int id=Integer.parseInt(session.getAttribute("sid").toString());
		System.err.println(id+"---"+ts.noticestaff(id, date));
		model.addAttribute("nots", ts.noticestaff(id, date));
		return cy.selectCalendarByid(a,staff_id);
	}
	
	@RequestMapping("hr-positive")
	public void hrpositive() {
	}
	/*@RequestMapping("selectpositive")
	@ResponseBody
	public JSONArray selectpositive() {
		Date date=new Date(sj.getNetworkTime());
		String systemdate=(date.getYear()+1900)+","+(date.getMonth()+1)+","+date.getDate();
		return ds.selectPositive(systemdate);
	}
	@RequestMapping("zhuanzhengsure")
	@ResponseBody
	public void zhuanzhengsure(int staff_id) {
		ds.updateStaffBypositive(staff_id);
	}*/
}
